package preprocess;


import java.util.*;
import java.io.*;

public class CityStatsReader {
	
	
	private Map<String,CityStats> stats;
	
	public CityStatsReader(String csv) {
		stats = new HashMap<String,CityStats>();
		try {
			
			BufferedReader br = new BufferedReader(new FileReader(new File(csv)));
			String line;
			br.readLine(); // read off columns' titles
			while((line = br.readLine()) != null) {
				String[] tokens = line.split(",");
				
				for(int i=0; i<tokens.length;i++)
					tokens[i] = tokens[i].toLowerCase();
				
				String key = tokens[0]+"__"+tokens[1]+"__"+tokens[3];
				CityStats cs = stats.get(key);
				if(cs == null) {
					cs = new CityStats(tokens[0],tokens[1],tokens[3],tokens[2]);
					stats.put(key, cs);
				}
				
				int time_index = -1;
				if(tokens[4].equals("00-07")) time_index = 0;
				if(tokens[4].equals("08-13")) time_index = 1;
				if(tokens[4].equals("14-17")) time_index = 2;
				if(tokens[4].equals("18-24")) time_index = 3;	
				
				int nt = Integer.parseInt(tokens[5]);
				int nu = Integer.parseInt(tokens[6]);
				
				cs.nt[time_index] = nt;
				cs.nu[time_index] = nu;
			}
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}	
	}
	
	
	public CityStats get(String city, String state, String activity) {
		return stats.get(city.toLowerCase()+"__"+state.toLowerCase()+"__"+activity.toLowerCase());
	}
	
	public int size() {
		return stats.size();
	}
	
	
	public static void main(String[] args) {
		CityStatsReader csr = new CityStatsReader("D:/DATASETS/IN/NST_KDE/backup_1/cityTracksStatistics0-1000.csv");
		//System.out.println(csr.get("modena", "it", "cycling"));
		//System.out.println(csr.get("abomey-calavi", "bj", "cycling"));
		System.out.println(csr.get("Hamburg", "de", "cycling"));
	}

}
